package cn.NewsServlet;

import cn.NewsDao.NewsDao1;
import cn.NewsDao.NewsDao4;
import cn.NewsDaoImpl.NewsDaoImpl1;
import cn.NewsDaoImpl.NewsDaoImpl4;
import cn.entity.News1;
import cn.entity.News4;
import cn.entity.Text1;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;


@WebServlet("/chaxun")
public class ChaServlet extends HttpServlet {



    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        System.out.println("这是get请求");

    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        req.setCharacterEncoding("utf-8");
        String username=req.getParameter("username");
        String password=req.getParameter("password");
        Text1 text1 = new Text1();
        text1.setUsername(username);
        text1.setPassword(Integer.parseInt(password));

//           if(username.equals("admin")&&password.equals("1234")){
//
//           }
        req.getSession().setAttribute("text1" ,text1);
        req.getRequestDispatcher("index2.jsp").forward(req,resp);
            //resp.sendRedirect(req.getContextPath() +"index2.jsp");






       /* News4 news4 = new News4();

        NewsDao4 newsDao4 = new NewsDaoImpl4();
        List<News4> newsList = newsDao4.getNewsList();

        for (int i=0;i<newsList.size();i++){
            System.out.println(newsList.get(i).getPassword()+newsList.get(i).getUserName());
            req.getSession().setAttribute("text1" ,news4);
            req.getRequestDispatcher("index2.jsp").forward(req,resp);
            *//*if (newsList.get(i).getPassword()==password&&newsList.get(i).getUserName()==username){
                req.getSession().setAttribute("text1" ,news4);
                req.getRequestDispatcher("index2.jsp").forward(req,resp);

            }else {
                req.getRequestDispatcher("index2.jsp").forward(req,resp);
            }*//*
        }*/

    }



}
